﻿#include "mainwindow.h"
using namespace  std;

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    sdlg=new SalesDialog(this, this);
    pdlg=new PurchaseDialog(this, this);
    vdlg=new VipDialog(this, this);
    edlg=new ExitDialog(this);
    QTimer *timer = new QTimer;
    timer->setInterval(1000);
    timer->start();
    connect(timer, SIGNAL(timeout()),pdlg, SLOT(updata_time()));
    connect(timer, SIGNAL(timeout()),sdlg, SLOT(updata_time()));
    connect(timer, SIGNAL(timeout()),vdlg, SLOT(updata_time()));
    connect(sdlg, SIGNAL(salesClose(int)), this, SLOT(salesClosed()));
    connect(pdlg, SIGNAL(purchaseClose(int)), this, SLOT(purchaseClosed()));
    connect(vdlg, SIGNAL(vipClose(int)), this, SLOT(vipClosed()));
    connect(edlg, SIGNAL(exitClose(int)), this, SLOT(exitClosed()));
    setWindowFlags(windowFlags()& ~Qt::WindowMaximizeButtonHint);
    setFixedSize(this->width(), this->height());
}

MainWindow::~MainWindow()
{
    delete sdlg;
    delete vdlg;
    delete pdlg;
    delete edlg;
    delete ui;
    qDebug()<<"mainwindow delete";

}

void MainWindow::closeEvent(QCloseEvent *event)
{
    event = event;
    edlg->show();
    //QApplication::exit(0);
}

void MainWindow::on_Sales_button_clicked()
{
    sdlg->show();
    this->hide();

}

void MainWindow::on_Purchase_button_clicked()
{
    pdlg->update_purchaseinfo();
    pdlg->show();
    this->hide();
}

void MainWindow::on_Vip_button_clicked()
{
    vdlg->update_vipinfo();     //刷新界面数据
    vdlg->show();
    this->hide();
}

void MainWindow::on_Exit_button_clicked()
{
    edlg->show();
    this->hide();
}

void MainWindow::salesClosed()
{
    sdlg->hide();
    this->show();
}

void MainWindow::purchaseClosed()
{
    this->show();
    pdlg->hide();
}

void MainWindow::vipClosed()
{
    this->show();
    vdlg->hide();
}

void MainWindow::exitClosed()
{
    this->show();
    edlg->hide();
}
